package com.cskaoyan.catmall.utils;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Author xyz
 * @Date 2021/12/16 22:07
 * @email 1924086038@qq.com
 **/
public class MD5Util {

    public static String encrypt(String str) {
        // 加盐
        String salt = "@@5dfddfsdfssffsdfsf6gggggggg389u3";
        str += salt;
        byte[] digest = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("md5");
            digest  = md5.digest(str.getBytes("utf-8"));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String md5Str = new BigInteger(1, digest).toString(16);
        return md5Str;
    }

}